<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;

/**
 * 实名认证
 *
 * @icon fa fa-circle-o
 */
class UserSmrz extends Backend
{

    /**
     * UserSmrz模型对象
     * @var \app\admin\model\UserSmrz
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\UserSmrz;

    }
    public function index()
    {
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            foreach ($list as &$value){
                $group=Db('user')->where('id',$value['uid'])->find();
                $value['uid']=$group['nickname'];
                $group=Db('user_group')->where('id',$value['gllx'])->find();
                $value['gllx']=$group['name'];
                $danwei=Db('danwei')->where('id',$value['dawe'])->find();
                $value['dawe']=$danwei['name'];
                $bumen=Db('bumen')->where('id',$value['bume'])->find();
                $value['bume']=$bumen['name'];
                $zzfg=Db('zizhefeng')->where('id',$value['zzfg'])->find();
                $value['zzfg']=$zzfg['name'];
                $fwxx=Db('fwxx')->where('id',$value['fwid'])->find();
                $value['fwxx']=$fwxx['title'];
                $value['status']=str_replace([0,1,2],['待审核','已通过','已驳回'],$value['status']);
            }
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }
    /**
     * 审核
     */
    public function examine(){
        $id=$this->request->param('ids');
        $status=$this->request->param('status');
        $smrz=$this->model->where('id',$id)->find();
        $sm_re=$this->model->where('id',$id)->update(['status'=>$status]);
        if($sm_re){
           if($status==1){
               $re =Db('user')
                   ->where('id',$smrz['uid'])
                   ->update(['username'=>$smrz['username'],'mobile'=>$smrz['mobile'],'group_id'=>$smrz['gllx']]);
           }
        }
//        if($re||$status==2) {
            echo "<script>alert('审核成功');window.location.href='/admin/user_smrz/index?addtabs=1'</script>";
//        }
    }
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


}
